<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>添加字段</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="/woniu/Public/X-admin/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form" method="post" action="" >
            	
                <!-- 为专业添加字段 -->
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">字段：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="question" name="question" required="" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                    <div id="questions" class="layui-form-mid layui-word-aux"> * 请填写英文字段</div>
                </div>

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button disabled id="btn"  class="layui-btn" lay-filter="add" lay-submit="">提交</button>
                </div>
            </form>
        </div>
        <script src="/woniu/Public/X-admin/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="/woniu/Public/X-admin/js/x-layui.js" charset="utf-8">
        </script>
        <script>

            layui.use(['form','layer'], function(){
                $ = layui.jquery;
              var form = layui.form();
              layer = layui.layer;

              ques = false;
              //姓名匹配
              $("#question").blur(function(){
                question = $(this).val();
                if(question.match(/[a-zA-Z][a-zA-Z0-9]{1,20}/)){
                    $("#questions").text("通过");
                    $("#questions").css('color',"#999");
                    ques = true;
                    $("#btn").attr("disabled",false);
                }else{
                    $("#questions").text("字段名格式错误");
                    $("#questions").css('color',"red");
                    ques = false;
                    $("#btn").attr("disabled",true);
                }
              });


              //监听提交
              form.on('submit(add)', function(data){
                
                question = $("#question").val();
                $.post('/woniu/index.php/Home/Major/doaddfield',{question:question},function(data){
                    if(data=="添加失败"){
                        alert('数据添加失败');
                        return false;
                    }
                });
                layer.alert("添加成功", {icon: 6,time:2000},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
                return false;
              });
            }); 
        </script>
    </body>

</html>